package org.example.game.history;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2024/06/23 10:46
 */
public class Solution100334 {

    public static void main(String[] args) {
        Solution100334 solution100334 = new Solution100334();
        System.out.println(solution100334.minimumArea(new int[][]{{0,0},{1,0}}));
    }

    public int minimumArea(int[][] grid) {
        int hMin = Integer.MAX_VALUE;
        int hMax = -1;
        int lMin = Integer.MAX_VALUE;;
        int lMax = -1;

        int maxH = grid.length - 1;
        int maxL = grid[0].length - 1;

        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid[i].length; j++) {

                if(grid[i][j] == 1){
                    hMin = Math.min(hMin, i);
                    hMax = Math.max(hMax, i);

                    lMin = Math.min(lMin, j);
                    lMax = Math.max(lMax, j);
                }

                if(lMax == maxL
                        && lMin == 0
                        && hMax == maxH
                        && hMin == 0){
                    return (hMax - hMin + 1) * (lMax - lMin + 1);
                }
            }
        }

        if(hMin == Integer.MAX_VALUE){
            return 0;
        }

        return (hMax - hMin + 1) * (lMax - lMin + 1);
    }

}
